package com.gitee.hermer.engine.jars.core.loader.event;

import java.io.File;
import java.io.IOException;

import com.gitee.hermer.boot.jee.commons.collection.StringCache;
import com.gitee.hermer.boot.jee.commons.encrypt.Md5Utils;
import com.gitee.hermer.boot.jee.commons.utils.FileUtils;
import com.gitee.hermer.boot.jee.commons.utils.StringUtils;
import com.gitee.hermer.boot.jee.commons.verify.Assert;
import com.gitee.hermer.engine.jars.core.domain.EngineConstant;
import com.gitee.hermer.engine.jars.core.event.EngineHandleEvent;

public class EngineAppInitializationEvent extends EngineHandleEvent{
	
	private String project;
	private String version;
	private String fileMd5;
	@Deprecated
	private String[] basePackages;

	public EngineAppInitializationEvent(String id) {
		super(id);
	}
	
	public EngineAppInitializationEvent(String id,File source) {
		super(id, source);
	}
	
	public EngineAppInitializationEvent(File source, String project, String version, String... basePackages) throws IOException {
		this(new StringCache(project).append(EngineConstant.STR_SPLIT).append(version).toString(), source);
		Assert.hasText(project);
		this.project = project;
		this.version = version;
		fileMd5 = StringUtils.toHexString(Md5Utils.md5(FileUtils.readBytes(source)));
		this.basePackages = basePackages;
	}
	
	public String getFileMd5() {
		return fileMd5;
	}
	
	public String getCacheKey(){
		return new StringCache(project).append("-").append(version).toString();
	}
	
	public String getProject() {
		return project;
	}

	public String getVersion() {
		return version;
	}
	@Deprecated
	public String[] getBasePackages() {
		return basePackages;
	}
	
	
	

}
